package cn.edu.hubu.hubusmartmedicalsystem.service.impl;

import cn.edu.hubu.hubusmartmedicalsystem.entity.Dept;
import cn.edu.hubu.hubusmartmedicalsystem.mapper.DeptMapper;
import cn.edu.hubu.hubusmartmedicalsystem.service.DeptService;
import cn.edu.hubu.hubusmartmedicalsystem.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class DeptServicelmpl implements DeptService
{
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public ResultVO<Dept> getDeptById(String deptId) {
        Dept dept = deptMapper.selectByDeptId(deptId);
        if (dept != null) {
            return new ResultVO<>(200, "查询成功", dept);
        } else {
            return new ResultVO<>(500, "未找到该部门", null);
        }
    }

    @Override
    public ResultVO<List<Dept>> getAllDepts() {
        List<Dept> deptList = deptMapper.selectAllDepts();
        if (deptList != null && !deptList.isEmpty()) {
            return new ResultVO<>(200, "查询成功", deptList);
        } else {
            return new ResultVO<>(500, "没有部门信息", null);
        }
    }

    @Override
    public ResultVO<String> addDept(Dept dept) {
        int result = deptMapper.insertDept(dept);
        if (result > 0) {
            return new ResultVO<>(200, "部门添加成功", null);
        } else {
            return new ResultVO<>(500, "部门添加失败", null);
        }
    }

    @Override
    public ResultVO<String> deleteDeptById(String deptId) {
        int result = deptMapper.deleteByDeptId(deptId);
        if (result > 0) {
            return new ResultVO<>(200, "部门删除成功", null);
        } else {
            return new ResultVO<>(500, "部门删除失败", null);
        }
    }

    @Override
    public ResultVO<String> updateDept(Dept dept) {
        int result = deptMapper.updateDept(dept);
        if (result > 0) {
            return new ResultVO<>(200, "部门信息更新成功", null);
        } else {
            return new ResultVO<>(500, "部门信息更新失败", null);
        }
    }
}
